﻿<DockPanel x:Class="SQLQuery.UI.Comparsion.DataComparsionControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:local="clr-namespace:SQLQuery.UI.Comparsion"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
    <DockPanel.Resources>
        <HierarchicalDataTemplate x:Key="DescriptionTemplate" ItemsSource="{Binding Childs}">
            <StackPanel  Orientation="Horizontal" >
                <TextBlock Text="{Binding Name}" Foreground="{Binding FontColor}"/>
                <TextBlock Text="{Binding Description}"/>
            </StackPanel >
        </HierarchicalDataTemplate>
        <Style x:Key="treeviewStyle" TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected}"/>
        </Style>
        <local:TotalCellTemplateSelector x:Key="totalCellTemplateSelector" />
    </DockPanel.Resources>
    <Grid>
        <dxdo:DockLayoutManager>
            <dxdo:LayoutGroup>
                <dxdo:LayoutGroup Width="3*" Orientation="Vertical">
                    <dxdo:LayoutPanel Name="tv1panel" Caption="目标数据" AllowClose="False" AllowHide="False">
                        <TreeView  Name="tv1" 
                           ItemsSource="{Binding Path=DataSourceList}"
                           SelectedItemChanged="TreeView_SelectedItemChanged"
                           ItemTemplate="{StaticResource DescriptionTemplate}"
                           ItemContainerStyle="{StaticResource treeviewStyle}"/>
                    </dxdo:LayoutPanel>
                    <dxdo:LayoutPanel Name="tv2panel" Caption="源数据" AllowClose="False" AllowHide="False">
                        <TreeView  Name="tv2"  
                           ItemsSource="{Binding Path=TargetSourceList}"
                           SelectedItemChanged="TreeView_SelectedItemChanged"
                           ItemTemplate="{StaticResource DescriptionTemplate}"
                           ItemContainerStyle="{StaticResource treeviewStyle}"/>
                    </dxdo:LayoutPanel>
                </dxdo:LayoutGroup>
                <dxdo:LayoutGroup Width="7*" Orientation="Vertical">
                    <dxdo:LayoutPanel Name="masterpanel" Caption="结果" AllowClose="False" AllowHide="False">
                        <dxg:GridControl Name="masterGrid">
                            <dxg:GridControl.Columns>
                                <dxg:GridColumn FieldName="IsUpdate" Header="是否更新"/>
                                <dxg:GridColumn FieldName="TableName" FixedWidth="True" Header="表名称" AllowEditing="False"/>
                                <dxg:GridColumn FieldName="TableStatus" Header="状态" AllowEditing="False"/>
                                <dxg:GridColumn FieldName="UpdateCount" Header="不同个数" AllowEditing="False"/>
                                <dxg:GridColumn FieldName="UpdateContent" Header="更新语句">
                                    <dxg:GridColumn.EditSettings>
                                        <dxe:MemoEditSettings MemoTextWrapping="Wrap" PopupMaxWidth="400" />
                                    </dxg:GridColumn.EditSettings>
                                </dxg:GridColumn>
                            </dxg:GridControl.Columns>
                            <dxg:GridControl.View>
                                <dxg:TableView Name="gridview" ShowAutoFilterRow="True" ShowGroupPanel="False" ShowIndicator="False" MultiSelectMode="Row" WaitIndicatorType="Panel" FocusedRowChanged="gridview_FocusedRowChanged" />
                            </dxg:GridControl.View>
                            <dxg:GridControl.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="反选" Click="MasterMenuSelect_Click"/>
                                </ContextMenu>
                            </dxg:GridControl.ContextMenu>
                        </dxg:GridControl>
                    </dxdo:LayoutPanel>
                    <dxdo:LayoutGroup>
                        <dxdo:LayoutPanel Caption="目标数据列" AllowClose="False" AllowHide="False">
                            <dxg:GridControl Name="sourceGrid" >
                                <dxg:GridControl.Resources>
                                    <DataTemplate x:Key="totalCellTemplate1">
                                        <Border Background="#FFF9E9FF" Margin="0,0,-1,0" Padding="2, 2, 2, 1" IsHitTestVisible="True">
                                            <TextBlock VerticalAlignment="Center" Foreground="Black" IsHitTestVisible="True" HorizontalAlignment="Right">
                                                <TextBlock.Text>
                                                    <Binding Path="Value" />
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </Border>
                                    </DataTemplate>
                                </dxg:GridControl.Resources>
                                <dxg:GridControl.Columns>
                                    <dxg:GridColumn FieldName="IsUpdate" Header="是否更新"/>
                                    <dxg:GridColumn FieldName="ColumnName" Header="列名" AllowEditing="False"/>
                                    <dxg:GridColumn FieldName="DataType" Header="类型" AllowEditing="False" CellTemplateSelector="{StaticResource totalCellTemplateSelector}"/>
                                    <dxg:GridColumn FieldName="IsNullable" Header="是否可空" AllowEditing="False" CellTemplateSelector="{StaticResource totalCellTemplateSelector}"/>
                                    <dxg:GridColumn FieldName="Length" Header="长度" AllowEditing="False" CellTemplateSelector="{StaticResource totalCellTemplateSelector}"/>
                                    <dxg:GridColumn FieldName="IsPrimaryKey" Header="是否主键"  AllowEditing="False" CellTemplateSelector="{StaticResource totalCellTemplateSelector}"/>
                                    <dxg:GridColumn FieldName="UpdateContent" Header="更新语句">
                                        <dxg:GridColumn.EditSettings>
                                            <dxe:MemoEditSettings MemoTextWrapping="Wrap" PopupMaxWidth="400" />
                                        </dxg:GridColumn.EditSettings>
                                    </dxg:GridColumn>
                                </dxg:GridControl.Columns>
                                <dxg:GridControl.View>
                                    <dxg:TableView Name="gridview1" ShowGroupPanel="False" ShowIndicator="False"  MultiSelectMode="Row" WaitIndicatorType="Panel" ScrollAnimationMode="EaseOut" 
                                                   ScrollViewer.ScrollChanged="gridview1_ScrollChanged"/>
                                </dxg:GridControl.View>
                            </dxg:GridControl>
                        </dxdo:LayoutPanel>
                        <dxdo:LayoutPanel Caption="源数据列" AllowClose="False" AllowHide="False">
                            <dxg:GridControl Name="targetGrid">
                                <dxg:GridControl.Columns>
                                    <dxg:GridColumn FieldName="IsUpdate" Header="是否更新" AllowEditing="False"/>
                                    <dxg:GridColumn FieldName="ColumnName" Header="列名" AllowEditing="False"/>
                                    <dxg:GridColumn FieldName="DataType" Header="类型" AllowEditing="False" />

                                    <dxg:GridColumn FieldName="IsNullable" Header="是否可空" AllowEditing="False"/>
                                    <dxg:GridColumn FieldName="Length" Header="长度" AllowEditing="False"/>
                                    <dxg:GridColumn FieldName="IsPrimaryKey" Header="是否主键" AllowEditing="False"/>
                                    <dxg:GridColumn FieldName="UpdateContent" Header="更新语句" AllowEditing="False"/>

                                </dxg:GridControl.Columns>
                                <dxg:GridControl.View>
                                    <dxg:TableView Name="gridview2" ShowGroupPanel="False" ShowIndicator="False"  MultiSelectMode="Row" WaitIndicatorType="Panel" 
                                                   ScrollViewer.ScrollChanged="gridview2_ScrollChanged"/>
                                </dxg:GridControl.View>
                            </dxg:GridControl>
                        </dxdo:LayoutPanel>
                    </dxdo:LayoutGroup>

                </dxdo:LayoutGroup>
            </dxdo:LayoutGroup>
        </dxdo:DockLayoutManager>
    </Grid>
</DockPanel>
